package com.aha.dataanalyzeandview.quartz;

import com.aha.dataanalyzeandview.utils.http.HttpClientUtil;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.quartz.QuartzJobBean;

@Slf4j
public class WxRobotSendMsgJob extends QuartzJobBean {
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 获取参数
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        // 业务逻辑 ...
        log.info("执行job[" + jobDataMap.get("title").toString() + "]------" + jobExecutionContext.getTrigger());

        String msg  = jobDataMap.get("msg").toString();
        String groupUrl = jobDataMap.getString("groupUrl");


        String paramStr = "{\"msgtype\": \"text\", \"text\": {\"content\": "+ msg +", \"mentioned_list\": [\"@all\"]}}";
        log.info("微信机器人发信：" + paramStr);

        String res = HttpClientUtil.sendPostByJson(groupUrl, paramStr, 1);
        log.info("发送消息的结果： " + res);
    }
}
